﻿<UserControl x:Class="PrestoDashboard.Tabs.ResolveVariableView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="700">

    <UserControl.DataContext>
        <Binding Source="{StaticResource ResolveVariableViewModel}"/>
    </UserControl.DataContext>
    
    <UserControl.Resources>
        <CollectionViewSource x:Key="VariablesViewSource" Source="{Binding ResolvedCustomVariables}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Key"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="45"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource StandardLabel}" Content="Application:"/>

        <StackPanel Orientation="Horizontal" Height="25" Grid.Row="0" Grid.Column="1">
            <TextBox Text="{Binding ApplicationWithGroup.Application.NameAndVersion, Mode=OneWay}" Width="360" IsEnabled="False"/>
            <Button Content="..." Height="25" Width="25" Command="{Binding SelectApplicationCommand}" />
        </StackPanel>

        <Label Grid.Row="1" Grid.Column="0" Style="{StaticResource StandardLabel}" Content="Override Groups:"/>

        <StackPanel Orientation="Horizontal" Height="40" Grid.Row="1" Grid.Column="1">
            <TextBox Text="{Binding ApplicationWithGroup.CustomVariableGroupNames, Mode=OneWay}" Width="360" Height="40"
                     VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True"/>
            <Button Content="..." Height="25" Width="25" Command="{Binding SelectGroupCommand}"/>
            <Button Content="X" Width="25" Height="25" Command="{Binding RemoveGroupCommand}"/>
        </StackPanel>

        <Label Grid.Row="2" Grid.Column="0" Style="{StaticResource StandardLabel}" Content="Server:"/>

        <StackPanel Orientation="Horizontal" Height="25" Grid.Row="2" Grid.Column="1">
            <TextBox Text="{Binding ApplicationServer.Name}" Width="360" IsEnabled="False"/>
            <Button Content="..." Height="25" Width="25" Command="{Binding SelectServerCommand}" />
        </StackPanel>
        
        <DataGrid Grid.Row="3" Grid.ColumnSpan="2" AutoGenerateColumns="False" IsReadOnly="True" HeadersVisibility="Column"
                      ItemsSource="{Binding Source={StaticResource VariablesViewSource}}" CanUserSortColumns="True">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Key}" Header="Variable" Width="220" SortMemberPath="Key"/>
                <DataGridTextColumn Binding="{Binding Path=Value}" Header="Value" Width="*"/>
            </DataGrid.Columns>
        </DataGrid>

        <Button Grid.Row="4" Grid.ColumnSpan="2" Style="{StaticResource StandardButton}" Content="Resolve"
                Command="{Binding ResolveCommand}" />
        
    </Grid>
    
</UserControl>
